import O1HD from "../../../engines/gameEngine";
import { CsvFileKind } from "../../../engines/libs/CsvFileKind";
import data_control from "../../../engines/libs/data_control";
import CsvDataManage from "../../../engines/managers/CsvDataManage";
import level_PeopleArcheryUnitBase from "../base/level_PeopleArcheryUnitBase";
import { peopleArcheryUnitTag } from "../const/peopleArcheryConst";

const {ccclass, property} = cc._decorator;

@ccclass
export default class level_peopleArcheryBox extends level_PeopleArcheryUnitBase {

    type:number = 0;

    @property({type:cc.Label,tooltip:"箱子文本"})
    lbText:cc.Label = null;

    @property({type:cc.Sprite,tooltip:"显示图片"})
    showSp:cc.Sprite = null;

    @property({type:cc.SpriteFrame,tooltip:"显示的图片"})
    showSps:cc.SpriteFrame[] = [];

    waveData:any = null;

    datas:any[] = [];

    /**绑定数据 */
    bindData(type:number,waveData:any){
        this.type = type;
        this.waveData = waveData;
        this.loadDatas();
        this.refrenshText();
        this.refrenshShow();
    }

    refrenshText(){
        let str = O1HD.getManagers().peopleArcheryManager.getOptionText(this.datas[0]);
        this.lbText.string = str;
    }

    refrenshShow(){
        this.showSp.spriteFrame = this.type == 1 ? this.showSps[1] : this.showSps[0];
    }

    update(dt: number): void {
        if(this.level.gamePauseFlag){
            return;
        }
        let moveDis = this.level.getRoleMoveSpd() * dt;
        this.node.y -= moveDis;
        this.autoDeath();
        super.update(dt);
    }

    onCollisionEnter(other: cc.Collider, self: cc.Collider): void {
        switch(other.tag){
            case peopleArcheryUnitTag.people:{
                    O1HD.getManagers().soundMgr.playSound("peopleArcherySound/Door");
                    this.openData();
                    this.unitDeath();
                break;
            }
        }
    }

    loadDatas(){
        let boxTypeId:string = "";
        switch(this.type){
                case 1:{
                    boxTypeId = this.waveData.big_drop_type;
                    break;
                }
                case 2:{
                    boxTypeId = this.waveData.middle_drop_type;
                }
                case 3:{
                    boxTypeId = this.waveData.little_drop_type;
                    break;
                }
            }
            let data = O1HD.getManagers().csvDataManager.getCsvDataItem(CsvFileKind.CsvFile.peopleArcheryBox,boxTypeId);
            let dropType = data["drop_type"];
            // 箱子打开动画
            // 不需要打开界面
            this.datas = this.level.getOptions(dropType,1);
    }
    
    openData(){
        // 不需要打开界面
        this.level.parseDataAddPeople(this.datas[0]);
    }

}
